package com.cong.juc;

import java.util.concurrent.CountDownLatch;

/**
 * CountDownLatch示例
 * @author cong
 * <p>
 * created on 2021/3/31 上午10:00
 */
public class CountDownLatchDemo2
{
    /**
     * 都over以后才可以离开
     * @param args
     */
    public static void main(String[] args) {
        CountDownLatch latch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(()->{
                latch.countDown();
                System.out.println(Thread.currentThread().getName()+"\t over");
            },String.valueOf(i)).start();
        }
        try {
            latch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"\t leave");
    }
}
